#ifndef OPENGLSHADERS_H
#define OPENGLSHADERS_H

const char * bwlabelfragshader_glsl = 
"varying vec2 tcoord;\n"
"uniform sampler2D tex;\n"
"uniform vec2 texelsize;\n"
"void main(void)\n"
"{\n"
"        bool set = false;\n"
"    if (texture2D(tex,tcoord).r == 1.0 && texture2D(tex,tcoord).g == 1.0\n"
"        && texture2D(tex,tcoord).b == 1.0)\n"
"    {\n"
"        vec4 outPx = vec4(0.0);\n"
"        outPx.rg = tcoord;\n"
"        outPx.b = 1.0;\n"
"        outPx.a = 0.0;\n"
"        set = true;\n"
"        gl_FragColor = outPx;\n"
"    }\n"
"    else if(texture2D(tex,tcoord).b == 1.0 && texture2D(tex,tcoord).a == 0.0){\n"
"        for(int xoffset = -1; xoffset <= 1; xoffset++)\n"
"            {\n"
"                    for(int yoffset = -1; yoffset <= 1; yoffset++)\n"
"                    {\n"
"if (xoffset == -1 || (xoffset == 0 && yoffset == -1)){\n"
"                    vec2 offset = vec2(xoffset,yoffset);\n"
"                                if(texture2D(tex,tcoord+offset * texelsize).b != 0.0){\n"
"                        gl_FragColor = texture2D(tex,tcoord+offset * texelsize);\n"
"                        set = true;\n"
"                        break;\n"
"                    }\n"
"\n"
"                }\n"
"                    }\n"
"            }\n"
"    }\n"
"    if(set == false){\n"
"        gl_FragColor = texture2D(tex,tcoord);\n"
"    }\n"
"}\n";

const char * dilatefragshader_glsl = 
"varying vec2 tcoord;\n"
"uniform sampler2D tex;\n"
"uniform vec2 texelsize;\n"
"void main(void)\n"
"{\n"
"        vec4 col = vec4(0.0);\n"
"        for(int xoffset = -1; xoffset <= 1; xoffset++)\n"
"        {\n"
"                for(int yoffset = -1; yoffset <= 1; yoffset++)\n"
"                {\n"
"                        vec2 loc = tcoord + vec2(xoffset,yoffset) * texelsize;\n"
"		bool test= loc.x > 0.00; \n"
"		test = test && loc.y > 0.00;\n"
"		test = test && loc.x < 1.0 && loc.y < 1.0;\n"
"                      	col = (test) ? max(col,texture2D(tex,loc)): col;\n"
"                }\n"
"        }\n"
"    gl_FragColor = clamp(col,vec4(0),vec4(1));\n"
"}\n";

const char * erodefragshader_glsl = 
"varying vec2 tcoord;\n"
"uniform sampler2D tex;\n"
"uniform vec2 texelsize;\n"
"void main(void)\n"
"{\n"
"        vec4 col = vec4(1.0);\n"
"        for(int xoffset = -1; xoffset <= 1; xoffset++)\n"
"        {\n"
"                for(int yoffset = -1; yoffset <= 1; yoffset++)\n"
"                {\n"
"                        vec2 offset = vec2(xoffset,yoffset);\n"
"                        col = min(col,texture2D(tex,tcoord+offset * texelsize));\n"
"                }\n"
"        }\n"
"    gl_FragColor = clamp(col,vec4(0),vec4(1));\n"
"}\n";

const char * simplefragshader_glsl = 
"varying vec2 tcoord;\n"
"uniform sampler2D tex;\n"
"void main(void)\n"
"{\n"
"    gl_FragColor = texture2D(tex,tcoord);\n"
"}\n";

const char * simplevertshader_glsl = 
"attribute vec4 vertex;\n"
"uniform vec2 offset;\n"
"uniform vec2 scale;\n"
"varying vec2 tcoord;\n"
"void main(void)\n"
"{\n"
"        vec4 pos = vertex;\n"
"        tcoord.xy = pos.xy;\n"
"    // -1, -1, 1,1 = 2\n"
"    vec2 toffset = vec2(-1,-1);\n"
"    vec2 tscale  = vec2(2,2);\n"
"\n"
"        pos.xy = pos.xy*tscale+toffset;\n"
"        gl_Position = pos;\n"
"}\n";

const char * threshfragshader_glsl = 
"varying vec2 tcoord;\n"
"uniform sampler2D tex;\n"
"uniform vec4 colU;\n"
"uniform vec4 colL;\n"
"void main(void)\n"
"{\n"
"\n"
"        vec4 texcol = texture2D(tex,tcoord);\n"
"\n"
"    bvec4 resultGT = greaterThanEqual(texcol,colL);\n"
"    bvec4 resultLT = greaterThanEqual(colU, texcol);\n"
"    resultGT.a = true;\n"
"    resultLT.a = true;\n"
"\n"
"    bool GT = all(resultGT);\n"
"    bool LT = all(resultLT);\n"
"\n"
"\n"
"   if (GT && LT){\n"
"        gl_FragColor = vec4(1.0,1.0,1.0,1.0);\n"
"    }\n"
"    else{\n"
"        gl_FragColor = vec4(0.0,0.0,0.0,0.0);\n"
"    }\n"
"}\n";



#endif 
